<template>
	<view >
		<button type="default" v-show="login_status1"open-type="getUserInfo" @getuserinfo="onGotUserInfo">登录</button>
		<view  v-show="login_status" style="z-index: 1;">
			<image style="width: 100%;position: relative;" :src="bgc" mode="aspectFill"></image>
		</view>
		
		<view  v-show="login_status" class="logoUrl">
			<image :src="logourl" style="width: 100%;height: 100%;border: 2px dotted #2D2D2D;
	border-radius: 100upx;" mode=""></image>
		</view>
		<view @click="changebgc" class="more">
			≡
		</view>
		<!-- 登录成功后显示的界面 -->
		<view v-show="login_status" class="body">
			<view class="fabu">
			<text>{{yifabu}} 已发布  {{beishoulu}} 被收录</text>
			</view>
			<view style="padding-left: 30upx;">
				<text style="color: #2D2D2D;font-weight: 600;" >{{name}}</text></br>
				<text  style="color: #6a6a6a;font-weight: 500;font-size: 25upx;">{{city}}</text>
			</view>
			<view class="tab">
				<button class="yifabu" @click="fabuclick" size="mini">已发布</button>
				<button class="beishoulu" @click="shouluclick" size="mini">被收录</button>
				
			</view>
			<view v-if="fabushow" style="width: 50%;height: 1upx;border-top: solid #717171 1px;margin-top: 10upx;float: left;margin-bottom: 20upx;"></view>
			<view v-if="shoulushow" style="width: 50%;height: 1upx;border-top: solid #717171 1px;margin-top: 10upx;float: right;"></view>
			<view v-show="fabushow" class="yifabu-main">
				<waterfall ref="shuaxin"></waterfall>
			</view>
			<view class="beishoulu-main" v-show="shoulushow">
				<waterfall1 ref="shuaxin1"></waterfall1>
			</view>
		</view>
		</view>
</template>

<script>
	import http from '../../utils/http.js';
	import Vue from "vue";
	export default {
		data() {
			return {
				name:"",
				city:"",
				gender:"",
				logourl:"",
				fabushow:true,
				shoulushow:false,
				login_status:true,
				login_status1:false,
				openid:"",
				bgc:"../../static/bgc.jpg",
				yifabu:"0",
				beishoulu:"0"
				
			}
		},
		onPullDownRefresh() {
		        //监听下拉刷新动作的执行方法，每次手动下拉刷新都会执行一次
		        console.log('refresh');
		        setTimeout(function () {
		            uni.stopPullDownRefresh();  //停止下拉刷新动画
		        }, 1000);
		    },
		onLoad:function(){
			
			var res = global.isLogin();
			console.log(res);
			
			var that = this;
			var res1 = uni.getStorageSync("openid");
			console.log("res1"+res1);
			if(res1!=null){
				that.name = uni.getStorageSync("name");
				that.city = uni.getStorageSync("city");
				that.logourl = uni.getStorageSync("logourl");
				that.openid = uni.getStorageSync("openid");
			}
			
		},
		onShow:function(){
			var res = global.isLogin();
			var openidfalse = uni.getStorageSync("openid");
			console.log(res);
			if(!res){
				uni.navigateTo({
					url:"./login"
				})
			}
			
			//console.log(options);
			var res = global.isLogin();
			console.log(res);
			if(res!=false){
				var that = this;
				var pages = getCurrentPages();
				var currPage = pages[pages.length - 1]; //当前页面
				let res1 = currPage.data.userdata;
				console.log(res)//为传过来的值
				//this.type = res.item
				if(res1!=undefined){
					that.name = res1.item.name;
					that.city = res1.item.city;
					that.logourl = res1.item.imageurl;
					that.openid = res1.item.openid;
					uni.setStorageSync("name",that.name);
					uni.setStorageSync("city",that.city);
					uni.setStorageSync("logourl",that.logourl);
					uni.setStorageSync("openid",that.openid);
					console.log("这里的：",res1.item.openid,"，",res1.item.name,res1.item.imageurl);
				}
				
				}
				if(res!=false){
					http.searchidExist({
					openid:uni.getStorageSync("openid")
				}).then(list=>{
					console.log(list);
					if(list.data=="fail"){
						http.insertUser({
							openid:uni.getStorageSync("openid"),
							name:that.name,
							logourl:uni.getStorageSync("logourl")
						}).then(list=>{
							console.log(list);
						})
					}
				})
				
				}
				http.returnBackground({
					openid:uni.getStorageSync("openid")
				}).then(list=>{
					console.log(list);
					if(list.data=="1"){
						this.bgc="../../static/bgc.jpg";
					}else{
						
						this.bgc="https://www.camwork.site/rescourse/background/"+list.data;
					}
				})
			console.log("内收录",uni.getStorageSync("beishoulu"));
			this.$refs.shuaxin.shuaxin();
			this.$refs.shuaxin1.update();
			this.yifabu = uni.getStorageSync("yifabu")
			this.beishoulu = uni.getStorageSync("beishoulu")
		},
		mounted:function(){
			console.log(this.bgc)	
		},
		
		methods: {
			fabuclick:function(){
				this.fabushow=true;
				this.shoulushow=false;
			},
			shouluclick:function(){
				this.fabushow=false;
				this.shoulushow=true;
			},
			getUserInfo:function(res){
				console.log(res);
			},
			changebgc:function(){
				
				uni.navigateTo({
					
					url:"./changephoto"
				})
			},
			// 登录
		 // changeLogin(){
			// // 授权
			// // 获取用户详细信息, 可以获取到说明已经授权过, 直接拿到用户信息
			// uni.login({
			// 	provider:"weixin",
			// 	success:function(loginres){
			// 		let js_code = loginres.code;
			// 		console.log(js_code);
			// 		uni.getUserInfo({
			// 			provider: 'weixin',
			// 			//授权成功的回调
			// 			success(res) {
			// 				uni.showToast({
			// 				    title:'授权成功',
			// 					icon:'none'
			// 				})
			// 				//console.info(res.data)
			// 				//that.login(res.data);//授权成功调用自己的登录方法就可以了
			// 			},
			// 			//第一次进入小程序
			// 			fail() {
			// 				uni.showToast({
			// 					title: '请点击授权进行登录',
			// 					icon: 'none'
			// 				});
			// 			}
			// 		});
			// 	}
			// })
			
		 //  },
		 
		
		}
	}
</script>

<style>
.logoUrl{
	position: absolute;
	width: 200upx;
	height: 200upx;
	border-radius: 100upx;
	z-index: 100;
	margin-top: -50px;
	left: 30upx;
	background-color: #FFFFFF;
}
.body{
	width: 100%;
	height: 1000upx;
	 border-radius: 25upx 25upx 0 0;
	background-color: #ffffff;
	margin-top: -30upx;
	padding-top: 150upx;
	position: absolute;
	overflow-x: hidden;
	overflow-y: hidden;
}
.fabu{
	position: absolute;
	top: 30upx;
	right: 50upx;
	font-weight: 700;
	font-size: 30upx;
}
.tab{
	width: 100%;
	height: 50upx;
	margin-top: 20upx;
	margin-left: 8upx;
}
.yifabu{
	width: 49%;
	list-style: none;
	background-color: transparent;
	outline: none;
	border: none;
}
.yifabu::after{
	border:none;
	border-radius: 0;
}
.beishoulu{
	width: 49%;
	list-style: none;
	background-color: transparent;
	outline: none;
	border: none;
}
.beishoulu::after{
	border: none;
}
.more{
	width: 50upx;
	height: 50upx;
	position: absolute;
	top: 370upx;
	right: 30upx;
	font-size: 50upx;
	color: #FFFFFF;
}
</style>
